package com.vn.ducktohome.screen.play;

import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.vn.ducktohome.constant.Constant;
import com.vn.ducktohome.gamelogic.GameControl;
import com.vn.ducktohome.helper.MyInput;
import com.vn.ducktohome.screen.PlayScreen;

public class DuckGroup extends Group {
	private int duckNumber = 3;
	private StaticDuck strayDuck, homeDuck;
	private Image motherDuck;
	private DynamicDuck duck;
	private LacosteGroup lacosteGroup;
	private boolean bCheckRemain = false; 

	public DuckGroup(LacosteGroup lacosteGroup) {
		super();
		
		this.lacosteGroup = lacosteGroup;
		bCheckRemain = false;
		motherDuck = new Image(GameControl.getAtlas().findRegion("play/duck-mother"));
		motherDuck.setX(Lake.X_CENTER - motherDuck.getWidth()/2);
		motherDuck.setY(Lake.Y_CENTER);
		addActor(motherDuck);
		
		strayDuck = new StaticDuck(duckNumber, true);
		strayDuck.setPosition(75, 420);
		
		homeDuck = new StaticDuck(0);
		homeDuck.setPosition(230, 200);

		duck = new DynamicDuck(this);
		
		addActor(strayDuck);
		addActor(homeDuck);
		addActor(duck);
		if (Constant.DEBUG)
			addActor(duck.point);
	}
	
	public void goHome() {
		strayDuck.decrease();
		homeDuck.increase();
		
//		duck.setVisible(false);
//		if (getRemaining() > 0)
//			duck.init();
	}
	
	@Override
	public void act(float delta) {
		super.act(delta);
		if (getRemaining() == 0)
			if (bCheckRemain == false){
				bCheckRemain = true;
				Constant.incLevel();
				PlayScreen.duckWin();
		}
		if (Constant.DEBUG)
			if (MyInput.pressKey(Keys.N)){
				bCheckRemain = true;
				Constant.incLevel();
				PlayScreen.duckWin();
			}
	}

	public int getRemaining() {
//		System.out.println("strayDuck.getN() : " + strayDuck.getN());
		return strayDuck.getN();
	}
	
	public LacosteGroup getLacosteGroup(){
		return lacosteGroup;
	}
}